// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CloudStorageAccountManagerExtensions.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Exception for errors when handling Windows Azure Cloud Drives.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

using Microsoft.WindowsAzure.StorageClient;

namespace AzureContrib.WindowsAzure.StorageClient
{
	/// <summary>
	/// Extensions on <see cref="ICloudStorageAccountManager"/>
	/// </summary>
	public static class CloudStorageAccountManagerExtensions
	{
		/// <summary>
		/// Get a <see cref="ICloudQueue"/> from the <paramref name="context"/> and <paramref name="queueName"/>
		/// </summary>
		/// <param name="cloudStorageAccountManager">Manager to work with</param>
		/// <param name="context">The named data context</param>
		/// <param name="queueName">The queue to access</param>
		/// <returns>The <see cref="ICloudQueue"/>.</returns>
		[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Assumes.NotNull handles null checking.", Scope = "method")]
		public static ICloudQueue GetQueueReference(this ICloudStorageAccountManager cloudStorageAccountManager, string context, string queueName)
		{
			Assumes.NotNull(cloudStorageAccountManager, "cloudStorageAccountManager");
			ICloudStorageAccount storageAccountByContext = cloudStorageAccountManager.GetStorageAccount(context);
			ICloudQueueClient cloudQueueClient = storageAccountByContext.CreateCloudQueueClient();
			ICloudQueue queueReference = cloudQueueClient.GetQueueReference(queueName);
			return queueReference;
		}

		/// <summary>
		/// Get a <see cref="CloudBlobContainer"/> reference from the <paramref name="cloudStorageAccountManager"/>
		/// </summary>
		/// <param name="cloudStorageAccountManager">A <see cref="ICloudStorageAccountManager"/> to fetch the <see cref="ICloudStorageAccount"/> from.</param>
		/// <param name="context">The named data context</param>
		/// <returns>The <see cref="CloudBlobContainer"/>.</returns>
		[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Assumes.NotNull handles null checking.", Scope = "method")]
		public static ICloudBlobClient GetCloudBlobClient(this ICloudStorageAccountManager cloudStorageAccountManager, string context)
		{
			Assumes.NotNull(cloudStorageAccountManager, "cloudStorageAccountManager");
			ICloudStorageAccount storageAccountByContext = cloudStorageAccountManager.GetStorageAccount(context);
			return storageAccountByContext.CreateCloudBlobClient();
		}

		/// <summary>
		/// Get a <see cref="CloudBlobContainer"/> reference from the <paramref name="cloudStorageAccountManager"/>
		/// </summary>
		/// <param name="cloudStorageAccountManager">A <see cref="ICloudStorageAccountManager"/> to fetch the <see cref="ICloudStorageAccount"/> from.</param>
		/// <param name="context">The named data context</param>
		/// <returns>The <see cref="CloudBlobContainer"/>.</returns>
		[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "Assumes.NotNull handles null checking.", Scope = "method")]
		public static ICloudTableClient GetCloudTableClient(this ICloudStorageAccountManager cloudStorageAccountManager, string context)
		{
			Assumes.NotNull(cloudStorageAccountManager, "cloudStorageAccountManager");
			ICloudStorageAccount storageAccountByContext = cloudStorageAccountManager.GetStorageAccount(context);
			ICloudTableClient cloudTableClient = storageAccountByContext.CreateCloudTableClient();
			return cloudTableClient;
		}
	}
}